package com.c.ctgproject.ui.newvehicles

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.c.ctgproject.retrofit.HttpHelper
import com.c.ctgproject.retrofit.Response
import com.c.ctgproject.retrofit.Service
import com.c.ctgproject.utils.MyLog
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import okhttp3.MultipartBody
import kotlin.collections.ArrayList

class NewvehiclesViewModel : ViewModel() {
    private val responsedata: MutableLiveData<Response<*>> = MutableLiveData()
    private val serviece = HttpHelper.getInstance().create(Service::class.java)

    fun getresponsedata(): MutableLiveData<Response<*>> {
        return responsedata
    }

    //新建车辆
    fun AddEntranceCar(token: String, parts: ArrayList<MultipartBody.Part>) {
        serviece.addEntranceCar(token, parts)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<Response<*>> {
                override fun onError(e: Throwable) {
                    Log.d("错误信息", "" + e.message)
                    e.printStackTrace()
                }

                override fun onComplete() {}
                override fun onSubscribe(d: Disposable) {}
                override fun onNext(userBeanResponse: Response<*>) {
                    MyLog.d("新建车辆回调:$userBeanResponse")
                    responsedata.value = userBeanResponse
                }
            })
    }
}